package com.JZ.QM.controller;

import com.JZ.QM.common.utils.CommonResult;
import com.JZ.QM.feign.CombinationFeignService;
import com.JZ.QM.service.ProYieldService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;

/**
 * @author cyc
 * @email cyc@gmail.com
 * @date 2020-06-22 22:35:36
 */
@RefreshScope
@RestController
@Slf4j
@RequestMapping("/proYields")
public class ProYieldController {
    @Resource
    ProYieldService proYieldService;
    @Resource
    CombinationFeignService combinationFeignService;

    /**
     * 获取组合中各个产品的收益率信息
     * @param comBaseId
     * @return
     */
    @RequestMapping("/proYieldByCombinationId")
    public CommonResult getProYieldByCombinationId(Long comBaseId){
        //组合中每个产品的信息
        ArrayList combinationShareSingles;
        //产品收益实体
        HashMap<String, Object> proResult;

        //获取组合的基本信息
        combinationShareSingles= (ArrayList) combinationFeignService.getCombinationShareInfoById(comBaseId).get("combinatiobShares");
        for (Iterator it = combinationShareSingles.iterator(); it.hasNext(); ) {
            LinkedHashMap iter = (LinkedHashMap) it.next();
            //获取产品的收益信息
            proResult=proYieldService.getProIncomes(iter.get("proTsCode").toString());
            iter.put("proIncome",proResult.get("proIncome"));
            iter.put("tradeDate",proResult.get("proTradeDate"));
        }
        return CommonResult.success().put("comBaseId",comBaseId).put("products",combinationShareSingles);
    }
}